package core

import (
	"bytes"
	"context"
	"golang.org/x/net/ipv4"
	"ntrace/enviroments"
)

type Sender interface {
	GetName() string
	StartSender() error
	StopSender()
}

type BaseSender struct {
	Ctx  context.Context
	Name string
	Task *TraceTask
	Stat *TraceStat

	Conn *ipv4.RawConn
}

func (s *BaseSender) GetName() string {
	return s.Name
}

func (s *BaseSender) StopSender() {
	if s == nil {
		return
	}

	if s.Conn != nil {
		s.Conn.Close()
	}
}

func AllocTxBuf(length int) []byte {
	payload := bytes.Repeat([]byte{0x5A}, length)
	copy(payload, enviroments.MagicNumber)
	return payload
}
